package com.example.dance.controller;

import com.example.dance.pojo.Result;
import com.example.dance.service.GetDataService;
import com.example.dance.util.ReturnResultUtil;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
public class GetDataController {
    @Autowired
    GetDataService getDataService;

    @PostMapping("/getVideosList")
    public Result getVideosList(@RequestBody Map<String, Object> params) {
        // 类型安全转换（避免直接强转）
        Integer type = (Integer) params.get("type");
        Integer currentLen = (Integer) params.get("currentLen");
        Integer num = (Integer) params.get("num");
        Integer currentKeyset = (Integer) params.get("currentKeyset");

        // 参数校验
        if (type == null || currentLen == null || num == null) {
            return ReturnResultUtil.failure("参数缺失");
        }

        System.out.printf("type:%d, currentLen:%d, num:%d,currentKeyset:%d%n", type, currentLen, num,currentKeyset);

        return ReturnResultUtil.success(getDataService.getVideosList(type,currentLen,currentKeyset,num));
    }

    @PostMapping("/getVideoPlay")
    public Result getVideo(@RequestBody Map<String, Object> params) {
        // 类型安全转换（避免直接强转）
        Integer videoId = (Integer) params.get("videoId");

        // 参数校验
        if (videoId == null) {
            return ReturnResultUtil.failure("参数缺失");
        }

        System.out.printf("videoId:%d%n", videoId);

        return ReturnResultUtil.success(getDataService.getVideoPlay(videoId));
    }

    @PostMapping("/getVideoPoints")
    public Result getVideoPoints(@RequestBody Map<String, Object> params) {
        // 类型安全转换（避免直接强转）
        Integer videoId = (Integer) params.get("videoId");

        // 参数校验
        if (videoId == null) {
            return ReturnResultUtil.failure("参数缺失");
        }

        System.out.printf("videoId:%d%n", videoId);

        return ReturnResultUtil.success(getDataService.getVideoPoints(videoId));
    }

}
